package com.haierCamera.customapplication.ui.main;

import android.app.Activity;
import android.content.Intent;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;

import com.haierCamera.customapplication.BaseActivity;
import com.haierCamera.customapplication.R;

import com.haierCamera.customapplication.databinding.HzklActivityAddStep2Binding;
import com.haierCamera.customapplication.ui.main.widget.DialogDeviceNotSupportWifi;

import androidx.databinding.DataBindingUtil;

public class HZKLCameraDeviceAddStepTwoActivity extends BaseActivity {

    HzklActivityAddStep2Binding binding;
    DialogDeviceNotSupportWifi dialogDeviceNotSupportWifi;

    private WifiInfo mWifiInfo;
    private String devType="";
    String ssid="";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = DataBindingUtil.setContentView(this, R.layout.hzkl_activity_add_step_2);
        binding.setLifecycleOwner(this);
        binding.imgReturn.setOnClickListener((v)->{
            finish();
        });

        binding.btnNext.setOnClickListener((v)->{
            startActivity(new Intent(this,HZKLCameraDeviceAddStepThreeActivity.class)
                    .putExtra("sn",getIntent().getStringExtra("sn"))
                    .putExtra("sc",getIntent().getStringExtra("sc"))
                    .putExtra("dt",getIntent().getStringExtra("dt"))
                    .putExtra("ssid",binding.edSsid.getText().toString())
                    .putExtra("ssidPwd",binding.edSsidPwd.getText().toString()));
        });

        binding.edSsidPwd.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!editable.toString().equals("")) {
                    binding.btnNext.setBackgroundDrawable(getResources().getDrawable(R.drawable.hzkl_btn_blue));
                    binding.btnNext.setClickable(true);
                } else {
                    binding.btnNext.setBackgroundDrawable(getResources().getDrawable(R.drawable.hzkl_btn_grey));
                    binding.btnNext.setClickable(false);
                }
            }
        });
        dialogDeviceNotSupportWifi = new DialogDeviceNotSupportWifi(this,R.style.HZKLSheetDialogStyle,this);
        binding.ivHelp.setOnClickListener((v)->{
            dialogDeviceNotSupportWifi.show();
        });

        WifiManager mWifiManager = (WifiManager) getApplicationContext().getSystemService(Activity.WIFI_SERVICE);
        mWifiInfo = mWifiManager.getConnectionInfo();
        if (mWifiInfo != null) {
            ssid=mWifiInfo.getSSID();
            ssid = ssid.substring(1,ssid.length()-1);
        }
        binding.edSsid.setText(ssid+"");
    }
}
